package com.jiao.databinding;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingComponent;
import androidx.databinding.DataBindingUtil;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.jiao.databinding.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        //上面一行相当于下面两行，ActivityMainBinding是根据布局activity_main生成的，所以能识别到是哪个布局
        ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        User user = new User("dd", 4);
        binding.setUser(user);

//        binding.textView.setText("可以直接获取控件");
        //事件监听
        binding.setEventHandle(new EventHandleListener(this));
        binding.setEventClick(new EventClick());
    }

    public class EventClick {
        public void buttonOnClick() {
            Toast.makeText(MainActivity.this, "喜欢", Toast.LENGTH_SHORT).show();
        }
    }
}